from research.calcor.dim1.ror_stat import ror_stat
"""as 
计算两个线的金叉死叉，或是差值距离的变化状态
"""
class gap_ror_stat:
    def __init__(self,timeperiod=1):
        self.roc=ror_stat(timeperiod=timeperiod)
    def oncalc(self,fast,slow,timekey=None):
        if fast is not None:
            if slow is not None:
                t=fast-slow
                return self.roc.oncalc(t,timekey)
            else:
                return None
        else:
            return None

if __name__ == '__main__':
    from jili.core import load, save
    from research.calcor.calcors_graph import graph_calcor
    k1m = load(r"D:\data\future_k1m_tq\TA005\TA005_20200102.pkl")
    gap_roc0=gap_ror_stat()
    cc = [{'calc_cmd': 'ta', 'cmd': 'EMA', 'out': ['ema30'], 'input': {'price': 'close'}, 'arg': {'timeperiod': 30},
           'batch': 30},
          {'calc_cmd': 'ta', 'cmd': 'EMA', 'out': ['ema10'], 'input': {'price': 'close'}, 'arg': {'timeperiod': 10},
           'batch': 10},
          {'calc_cmd': 'function', 'function': gap_roc0.oncalc, 'out': ['gap_roc0'], 'input': ["ema10","ema30","timekey"]}]
    c = graph_calcor(cc)
    k1ms = k1m[:32]
    for t in k1ms:
        t = c.onbar(t)
    print(t)
    t1 = k1m[32]
    t1["timekey"] = t["timekey"]
    t1 = c.onbar(t1)
    print(t1)
    print("end")